package cn.iocoder.yudao.module.ai.tool.function;

import cn.hutool.http.HttpUtil;
import com.alibaba.fastjson.JSONObject;
import com.fasterxml.jackson.annotation.JsonClassDescription;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.annotation.JsonPropertyDescription;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.springframework.ai.chat.model.ToolContext;
import org.springframework.stereotype.Component;

import java.util.HashMap;
import java.util.Map;
import java.util.function.BiFunction;

/**
 * 工具：工单详情查询
 * <p>
 * 同时，也是展示 ToolContext 上下文的使用
 *
 * @author Ren
 */
@Component("scarp_sheet_create")
public class ScrapSheetCreateToolFunction
        implements BiFunction<ScrapSheetCreateToolFunction.Request, ToolContext, String> {


    @Data
    @JsonClassDescription("创建报废单到系统，工单创建成功时，询问用户是否需要审批该工单")
    public static class Request {

        /**
         * 工单号
         */
        @JsonProperty(required = false, value = "userid")
        @JsonPropertyDescription("用户id")
        private String userId;


    }

    @Data
    @AllArgsConstructor
    @NoArgsConstructor
    @JsonClassDescription("创建报废单到系统，工单创建成功时，询问用户是否需要审批该工单")
    public static class Response {

        private Object data;


    }

    @Override
    public String apply(Request request, ToolContext toolContext) {
        Map<String, Object> map = new HashMap<>();
        map.put("userId", request.getUserId());
        String result = HttpUtil.createPost("http://192.168.1.168:38090/admin-api/storeroom/work-sheets/createScrapSheetsAI")
                .addHeaders(Map.of("Authorization", "d115a01f765b4b2987e46116efd08d7f"))
                .body(JSONObject.toJSONString(map))
                .execute()
                .body();
        return result;
    }

}
